<template>
    <div style="display: flex;">
        <div style="flex: 1">
            <el-input
                    type="textarea"
                    :rows="80"
                    placeholder="请输入内容"
                    v-model="str">
            </el-input>
        </div>
        <div style="display: flex;justify-content: center;width: 120px;">
            <div style="">
                <button @click="()=>triggervalue2json()">转化</button>
            </div>
        </div>


        <div style="flex: 1">
            <div @click="()=>copy2bang(JSON.stringify(resultJson,'',2))" style="cursor: pointer">复制</div>
            <el-input
                    type="textarea"
                    :rows="80"
                    placeholder="请输入内容"
                    :value="JSON.stringify(resultJson,'',2)">
            </el-input>
        </div>
    </div>
</template>
<script>

    function getUrlParams(str){
        var index=str.indexOf('?')
        if(index>=0){
            str=str.substring(index+1,str.length)
        }

        var array=str.split("&")
        var obj={}
        array.map(item=>{
            obj[item.split('=')[0]] =item.split('=')[1]
        })
        return obj
    }

    import {copy2bang} from '../../utils/utils';
    export default {
        data() {
            return {
                copy2bang,
                JSON,
                str: "", resultJson: ""
            }
        },
        methods: {
            triggervalue2json() {
                var str = this.str
                var array=str.split('\/')
                var opbj = getUrlParams(str)
                /*array.map(item => {
                    var pre="="
                    if(item.indexOf("=")>=0){
                        pre="="
                    }
                    if(item.indexOf("->")>=0){
                        pre="->"
                    }
                    var value=item.split(pre)[1].trim()
                    value=value.replaceAll('"','')
                    var key=item.split(pre)[0].trim()
                    key=key.replaceAll('"','')
                    if(value=='null'){
                        value=''
                    }
                    opbj[key] =value
                })*/
                array.map((value,index)=>{
                    opbj['path'+index]=value
                })
                console.log(opbj)
                this.resultJson = opbj


            }
        }
    }
</script>